package com.noble.meether.ui.wallet;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.noble.meether.R;
import com.noble.glamour.bean.center.user.detail.UserDetail;
import com.noble.glamour.module.logic.application.ModuleMgr;
import com.noble.glamour.module.util.UIShow;
import com.noble.library.base.BaseAppCompatActivity;
import com.noble.library.log.PToast;
import com.noble.library.observe.MsgMgr;
import com.noble.library.observe.MsgType;
import com.noble.library.observe.PObserver;
import com.noble.meether.MeetUIShow;

/**
 * 我的钱包
 */
public class MyWalletAct extends BaseAppCompatActivity implements View.OnClickListener, PObserver {
    private TextView tvMoney;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.wallet_layout);
        initView();
    }

    @Override
    protected boolean isStatusBarLight() {
        return false;
    }

    private void initView() {
        initTitle();
        tvMoney = findViewById(R.id.wode_wallet_tv_money);
        findViewById(R.id.wallet_draw).setOnClickListener(this);
        findViewById(R.id.wallet_declare).setOnClickListener(this);
        refreshView();
        MsgMgr.getInstance().attach(this);
    }

    private void initTitle() {
        setTitleBackground(getResources().getColor(R.color.transparent));
        setBackView(false);
        setTitle(getString(R.string.wallet_mine), getResources().getColor(R.color.white));
        setTitleRight(getString(R.string.wallet_detail), getResources().getColor(R.color.white), this);
    }

    public void refreshView() {
        UserDetail userDetail = ModuleMgr.getCenterMgr().getMyInfo();
        tvMoney.setText(String.valueOf(userDetail.getAmountCash()));
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.wallet_draw:      // 提现
                String money = tvMoney.getText().toString().trim();
                float minMoney = 50;  // 配置接口中拿
                if (Float.valueOf(money) <= minMoney) {
                    PToast.showShort(getString(R.string.withdraw_tips) + minMoney + getString(R.string.head_unit));
                    return;
                }
                MeetUIShow.showApplyAct(this, -1);
                break;

            case R.id.wallet_declare:
                UIShow.showWithDrawExplainAct(this);   //跳转到提现说明页
                break;
            case R.id.base_title_right_txt:
                MeetUIShow.showWalletDetailAct(this);
                break;
            default:
                break;
        }
    }

    @Override
    public void onMessage(String key, Object value) {
        switch (key) {
            case MsgType.MT_MyInfo_Change:
                refreshView();
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        MsgMgr.getInstance().detach(this);
    }
}
